package test.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class App {
	
	static List<User> users = Arrays.asList(new User[]{
			new User("zhangsan", 12, 1),
			new User("xiaoming", 25, 1),
			new User("xiaohong", 31, 2),
			new User("xiaogang", 29, 1),
			new User("xiaofang", 22, 2)});
	
	public static void main(String[] args) {
//		Map<Integer, Integer> map = users.stream().collect(Collectors.groupingBy(User::getSex, Collectors.reducing(0, User::getAge, Integer::sum)));
//		System.out.println(map);
//		
//		Map<Integer, Double> map2 = users.stream().collect(Collectors.groupingBy(User::getSex, Collectors.averagingInt(User::getAge)));
//		System.out.println(map2);
//		
//		Map<Integer, List<String>> map3 = users.stream().collect(Collectors.groupingBy(User::getSex, Collectors.mapping(User::getName, Collectors.toList())));
//		System.out.println(map3);
//		
		users = null;
		System.out.println(users.stream().map(e->e.getName()).collect(Collectors.toList()));
	}
	
	public void test(Object obj) {
		System.out.println(obj);
	}

}
